﻿using System.Collections.Generic;
using Medianamik.Core;
using Medianamik.Core.Configuration;
using System.Configuration;

namespace Medianamik.UI.Controls
{
    /// <summary>
    /// Contrôle permettant de choisir une image
    /// </summary>
    public class ImagePicker : BaseImagePicker, IMedianamikControl
    {
        private static MedianamikConfigSection _config =
            (MedianamikConfigSection)ConfigurationManager.GetSection(ConfigurationSectionName.MEDIANAMIK);

        private static readonly string[] _defaultImagePaths = new[] { _config.EditorImageFilesPath };
        protected HashSet<string> _imagePaths;
        protected override HashSet<string> ImagePaths
        {
            get
            {
                if (_imagePaths == null)
                {
                    string[] imageFilesPath;
                    if (CurrentSite == null || string.IsNullOrEmpty(CurrentSite.EditorImageFilesPath))
                    {
                        imageFilesPath = _defaultImagePaths;
                    }
                    else
                    {
                        imageFilesPath = new[] { CurrentSite.EditorImageFilesPath };
                    }

                    _imagePaths = new HashSet<string>(imageFilesPath);
                }
                return _imagePaths;
            }
        }
    }
}